package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esm.model.Department_lxy;
import com.esm.model.User;
import com.esm.service.UpdataDepartmentService_lxy;
import com.esm.serviceimpl.UpdDepSerImpl_lxy;

import net.sf.json.JSONObject;

/**
 * 这是一个修改部门Controller
 * @author LiuXingYu
 *
 */
public class UpdateDepartmentController_lxy extends HttpServlet{
	UpdataDepartmentService_lxy uds=new UpdDepSerImpl_lxy();
          @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        	// TODO Auto-generated method stub
        	  doPost(req, resp);
        }
          @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub
        	  HttpSession session=req.getSession();
        	  resp.setCharacterEncoding("utf8");
        	  PrintWriter pw=resp.getWriter();
        	  int deptId=Integer.parseInt(req.getParameter("deptId"));
        	  String deptName=req.getParameter("deptName");
        	  String manager=req.getParameter("manager");
        	  String currentName=((User)session.getAttribute("currentUser")).getUname();
        	  Department_lxy tempdepartment=new Department_lxy(deptId, deptName,manager);
        	  JSONObject j =new JSONObject();
        	  j.put("value", uds.updataDepartment(tempdepartment,currentName));
        	  pw.write(j.toString());
        	  pw.flush();
        	  pw.close();
        }
}
